package main

import (
	"flag"
	"jkgo/jk/jklog"
	"jkgo/jkbase"
	"findService/ss/jksys/jksys"
)

var sys_args jkbase.ConfigBaseArgs

var (
	cmd   = flag.String("cmd", "run", "run/install/remove service")
	conf  = flag.String("conf", "etc/findyouwant/jksys.json", "conf file")
	debug = flag.Bool("d", false, "debug mode")
)

func start() {
	jklog.L().Infof("Listen with [%s:%d]\n", sys_args.ClientAddr, sys_args.ClientPort)

	//_, _, err := jksys.Start(sys_args.Addr, sys_args.Port, sys_args.ClientAddr, sys_args.ClientPort, true, true)
	err := jksys.StartIoT(sys_args.ClientAddr, sys_args.ClientPort)
	if err != nil {
		jklog.L().Errorln("start error ", err)
		return
	}
}

func main() {

	flag.Parse()

	err := jkbase.GetConfigInfo(*conf, &sys_args)
	if err != nil {
		jklog.L().Errorf("get config %s failed %v\n", *conf, err)
		return
	}
	jklog.L().InitLog(sys_args.LogFile)
	if *debug {
		jklog.L().SetLevel(jklog.LEVEL_ALL)
	}
	jklog.L().Infoln("jksys program start...")
	jklog.L().Infoln("conf data ", sys_args)

	_, err = jkbase.InitProgramRun("jksys", "jk system program", start)
	if err != nil {
		jklog.L().Errorln(err)
		return
	}
	jklog.L().Infoln("jksys  program exit...")
}
